#ifndef _M_DICT_
#define _M_DICT_
#include <vector>
#include "sqlite3.h"
#include <string>
#define NO_STAR         -1
#define MAX_RECORDS     100
using std::string;
using std::vector;

namespace mdict {

typedef struct WordEntry {
    string word;
    vector<string> definition;
    vector<string> translation;
    string pronunciation;
    vector<string> examples;
    int collins_star = NO_STAR;
    vector<string> changes;
} wordentry_t;

class MachineDict {
public:
    MachineDict();
    ~MachineDict();
    vector<string> &get_definition_by_word(const string &word);
    vector<string> &get_translation_by_word(const string &word);
    string &get_pronunciation_by_word(const string &word);
    vector<string> &get_examples_by_word(const string &word);
    int get_collinsstar_by_word(const string &word);
    vector<string> &get_changes_by_word(const string &word);
    wordentry_t &get_allinfo_by_word(const string &word);
    vector<wordentry_t> &get_result_by_range(unsigned int start, unsigned int end);
    vector<wordentry_t> &get_result_vector();
    int store_callback(char **argv);
private:
    void query_by_word(const string &word);
    string m_last_queried;
    vector<wordentry_t> result_vec;
    sqlite3 *conn;
};
}; // namespace mdict
// 一些静态工具方法
int static_store_callback(void *data, int argc, char **argv, char **col_name);
void split_string(const string& s, vector<string>& v, const string& c);
int get_count_callback(void *result, int argc, char **argv, char **col_name);
#endif